<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *项目管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$manage_op=array('start','off');
if(in_array($_RQ['op'],$manage_op)){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择信息！','error');
	}
}
$return['sex']=$this->sex2;
$return['pay']=$this->xinzhis;
$return['job_type']=$this->job_type;
$return['job_paytype']=$this->job_paytype;
$return['job_baotype']=$this->job_baotype;
if($_RQ['op']=='list'){
	$params=array('type'=>0);
	$params['uniacid']=$_SESSION['uniacid'];
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if($_RQ['merchid']){
		$params['merchid']=intval($_RQ['merchid']);
		$return['params']['merchid']=$_RQ['merchid'];
	}
	if($_RQ['title']){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_51job_job',$params,array($pindex,$psize),$total,$fields,'','updatetime desc,createtime desc,id desc');
	if($list){
		foreach($list as &$item){
			$item['url']=custom_url('jy_51job/item_detail//id='.$item['id'],true);
			$merch=pdo_get('jy_51job_merch',array('id'=>$item['merchid'],'uniacid'=>$_SESSION['uniacid']));
			$item['merch']=$merch;
			$item['jobname']=pdo_getcolumn('jy_51job_job_group',array('id'=>$item['cid'],'uniacid'=>$_SESSION['uniacid']),'title');
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'职位信息列表'),
			array('op'=>'edit','title'=>'添加职位信息'),
		),
		'list'=>array('data'=>'list','tip'=>'<red>[温馨提示]：这里显示企业发布的职位</red>','edit'=>true,'list'=>array(
			array('name'=>'id','title'=>'ID','type'=>'string'),
			array('name'=>'merch.title','title'=>'公司名称','type'=>'string'),
			array('type'=>'string','title'=>'职位','name'=>'title'),
			array('type'=>'radio','title'=>'职位类型','name'=>'type','help'=>'','options'=>'job_type'),
			array('name'=>'zhaonum','title'=>'招聘人数','type'=>'string'),
			array('name'=>'sex','title'=>'性别要求','type'=>'radio','options'=>'sex'),
			array('name'=>'ageinfo','title'=>'年龄要求','type'=>'string'),
			array('name'=>'endtime','title'=>'到期时间','type'=>'time'),
			array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
			array('name'=>'updatetime','title'=>'刷新时间','type'=>'time'),
			array('name'=>'looks','title'=>'浏览数量','type'=>'string'),
			array('name'=>'status','title'=>'是否启用','type'=>'switch','set'=>'set'),
			array('name'=>'istop','title'=>'是否置顶','type'=>'radio','options'=>'istop'),
			array('name'=>'ishot','title'=>'是否热门','type'=>'switch','set'=>'set'),
			array('name'=>'url','title'=>'复制链接','type'=>'copy'),
			array('name'=>'url','title'=>'二维码','type'=>'ewm'),
		)),
		'search'=>array(
			array('type'=>'string','width'=>15,'title'=>'职位','name'=>'title'),
			array('name'=>'merchid','width'=>15,'title'=>'发布企业','type'=>'choose','action'=>'/get_merch/'),
			array('name'=>'status','width'=>15,'title'=>'是否启用','type'=>'select','width'=>'15','options'=>'select_status'),
		)
	);
	$return['sex']=$this->sex2;
	$return['job_type']=$this->job_type;
	$return['istop']=array('未置顶','已置顶');
	$return['select_status']=array(array('id'=>0,'title'=>'下架'),array('id'=>1,'title'=>'上架'));
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_51job_job',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$item['images']=json_decode($item['images'],true);
		$item['lat_lng']=json_decode($item['lat_lng'],true);
		$item['onlinetime']=json_decode($item['onlinetime'],true);
		$item['pcd']=json_decode($item['pcd'],true);
		$item['endtime'] =$item['endtime']?date('Y/m/d H:i',$item['endtime']):'';
		$item['updatetime'] =$item['updatetime']?date('Y/m/d H:i',$item['updatetime']):'';
		$item['createtime'] =$item['createtime']?date('Y/m/d H:i',$item['createtime']):'';
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回职位列表'),
		),
		'edit'=>array(
					array('type'=>'string','title'=>'职位名称','name'=>'title'),
					array('type'=>'select2','title'=>'职位分类','name'=>'pid','options'=>'pids','title2'=>'岗位2级分类','name2'=>'cid','options2'=>'cids'),
					array('name'=>'zhaonum','title'=>'招聘人数','type'=>'string'),
					array('type'=>'radio','title'=>'性别要求','name'=>'sex','help'=>'','options'=>'sex'),
					array('type'=>'string','title'=>'年龄要求','name'=>'ageinfo','help'=>'文字描述：例如：22岁~30岁'),
					array('type'=>'radio','title'=>'学历要求','name'=>'xueli','options'=>'xueli_type'),
					array('type'=>'radio','title'=>'职位类型','name'=>'type','help'=>'','options'=>'job_type'),
					array('type'=>'radio','title'=>'薪资类型','name'=>'paytype','help'=>'','options'=>'job_paytype'),
					array('type'=>'unitstring','title'=>'薪资','name'=>'price','unit'=>'/月','show'=>array('paytype'=>0)),
					array('type'=>'unitstring','title'=>'薪资','name'=>'price','unit'=>'/天','show'=>array('paytype'=>1)),
					array('type'=>'unitstring','title'=>'薪资','name'=>'price','unit'=>'/小时','show'=>array('paytype'=>2)),
					array('type'=>'unitstring','title'=>'薪资','name'=>'price','unit'=>'/次','show'=>array('paytype'=>3)),
					array('name'=>'onlinetime','title'=>'上班时间','type'=>'time_hour'),
					//array('type'=>'radio','title'=>'保险类型','name'=>'baotype','help'=>'','options'=>'job_baotype'),
					//array('type'=>'pcd','title'=>'地址','name'=>'pcd'),
					//array('type'=>'string','title'=>'地址','name'=>'address'),
					array('type'=>'lat_lng','title'=>'坐标','name'=>'lat_lng'),
				    array('name'=>'merchid','title'=>'发布企业','type'=>'choose','action'=>'jy_51job/get_merch/'),
					array('type'=>'richtext','title'=>'职位详情','name'=>'remark','help'=>''),
					array('type'=>'richtext','title'=>'福利待遇','name'=>'fuli','help'=>''),
					array('type'=>'images','title'=>'多图','name'=>'images','help'=>''),
					array('type'=>'string','title'=>'浏览量','name'=>'looks','help'=>''),
					array('name'=>'endtime','title'=>'到期时间','type'=>'time'),
					array('name'=>'createtime','title'=>'创建时间','type'=>'time'),
					array('name'=>'updatetime','title'=>'刷新时间','type'=>'time'),
					array('type'=>'switch','title'=>'是否启用','name'=>'status','help'=>'设置是否启用'),
					array('name'=>'paixu','title'=>'排序','type'=>'string'),
		)
	);
	$return['pids']=pdo_getall('jy_51job_job_group',array('pid'=>0,'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	foreach($return['pids'] as &$pv){
		$pv['cids']=pdo_getall('jy_51job_job_group',array('pid'=>$pv['id'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	}
	$return['xueli_type']=$this->xueli_type;
	foreach($return['xueli_type'] as &$xl){
		$xl=$xl.'以上';
	}
	$return['xueli_type'][0]='学历不限';
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if(!$postdata['title']){
		exi('职位名称不能为空！','error');
	}
	if(!$postdata['images']){
			//exi('图片不能为空！','error');
	}
	if(!$postdata['merchid']){
		exi('发布企业不能为空！','error');
	}
	if(empty($postdata['lat_lng'])){
			//exi('请选择坐标！','error');
	}
	/*if($postdata['pcd']){
		if($postdata['pcd']['city']){
			if($postdata['pcd']['city']=='北京市' || $postdata['pcd']['city']=='上海市' || $postdata['pcd']['city']=='天津市'){
				$address=$postdata['pcd']['city'].' 市辖区';
			}else{
				$address=$postdata['pcd']['province'].' '.$postdata['pcd']['city'];
			}
			$code=pdo_getcolumn('core_area',array('address'=>$address),'parent_code');
		}
	}*/
	$merch=pdo_get('jy_51job_merch',array('id'=>$postdata['merchid'],'uniacid'=>$_SESSION['uniacid']));
	$postdata['pcd']=json_decode($merch['pcd'],true);
	$jobname=pdo_getcolumn('jy_51job_job_group',array('id'=>$postdata['cid'],'uniacid'=>$_SESSION['uniacid']),'title');
	$company_title=pdo_getcolumn('jy_51job_merch',array('id'=>$postdata['merchid'],'uniacid'=>$_SESSION['uniacid']),'title');
	if(!$postdata['price']){
		$pay='面议';
	}else{
		$postdata['paytype']=$postdata['paytype']?:0;
		$pay=$postdata['price'].'元/'.$this->job_paytype2[$postdata['paytype']];
	}
	$data=array(
		'title'=>trim($postdata['title'])?:$company_title.'职位['.$jobname.']',
		'images'=>ijson_encode($postdata['images']),
		'pay'=>$pay,
		'merchid'=>intval($postdata['merchid']),
		'remark'=>trim($postdata['remark']),
		'fuli'=>trim($postdata['fuli']),
		'name'=>trim($postdata['name']),
		'mobile'=>trim($postdata['mobile']),
		'address'=>trim($postdata['address']),
		'status'=>intval($postdata['status']),
		'sex'=>intval($postdata['sex']),
		'province'=>$postdata['pcd']['province'],
		'city'=>$postdata['pcd']['city'],
		'district'=>$postdata['pcd']['district'],
		'code'=>$code,
		'looks'=>intval($postdata['looks']),
		'pid'=>intval($postdata['pid']),
		'cid'=>intval($postdata['cid']),
		'lat_lng'=>ijson_encode($postdata['lat_lng']),
		'onlinetime'=>ijson_encode($postdata['onlinetime']),
		'price'=>trim($postdata['price']),
		'paytype'=>trim($postdata['paytype']),
		'baotype'=>trim($postdata['baotype']),
		'paixu'=>intval($postdata['paixu']),
		'ageinfo'=>trim($postdata['ageinfo']),
		'xueli'=>intval($postdata['xueli']),
		'zhaonum'=>intval($postdata['zhaonum']),
		'createtime'=>strtotime($postdata['createtime']),
		'updatetime'=>strtotime($postdata['updatetime']),
		'endtime'=>strtotime($postdata['endtime']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_51job_job',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=$data['updatetime']=time();
		$data['type']=0;
		pdo_insert('jy_51job_job',$data);
	}
	exi('操作成功！','','list');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_51job_job',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的项目！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		pdo_update('jy_51job_job',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	if(isset($post['ishot'])){
		pdo_update('jy_51job_job',array('ishot'=>intval($post['ishot'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}
if($_RQ['op']=='zhiding'){
	$basic=$this->plugin_setting('basic');
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		if(!$id){
			exi('参数错误！','error');
		}
		if($post['packname']<1){
			exi('置顶数必须大于1！','error');
		}
		if(intval($post['iskou'])){
			$packnum=$post['packnum'];
			$packname=$post['packname'];
			if($packname==1){
				if(!$basic['topfeeday']){
					exi('还未设置按天数置顶费用，移步参数设置--置顶设置！','error');
				}
				$fee=$basic['topfeeday']*$packnum;
				$packtitle='天';
			}elseif($packname==2){
				if(!$basic['topfeeyue']){
					exi('还未设置按月数置顶费用，移步参数设置--置顶设置！','error');
				}
				$fee=$basic['topfeeyue']*$packnum;
				$packtitle='月';
			}elseif($packname==3){
				if(!$basic['topfeeji']){
					exi('还未设置按季数置顶费用，移步参数设置--置顶设置！','error');
				}
				$fee=$basic['topfeeji']*$packnum;
				$packtitle='季';
			}
			$title='置顶帖子收费：'.$packnum.'《'.$packtitle.'》';
			$jianfee=model('core/member')->cut_credit2($post['mid'],$fee,$title,'jy_51job');
			if(!$jianfee){
				exi('客户余额不够，付费置顶失败！','error');
			}
			if($packname==3){
				$packnum2=$packnum*120;
			}elseif($packname==2){
				$packnum2=$packnum*30;
			}else{
				$packnum2=$packnum;
			}
			if($item['topendtime']<TIMESTAMP){	
				$topendtime=TIMESTAMP+$packnum2*24*3600;
			}else{
				$topendtime =$item['topendtime']+$packnum2*24*3600;
			}
			$insert=array(
				'uniacid'=>$_SESSION['uniacid'],
				'mid'=>$post['mid'],
				'packname'=>$packname,
				'packnum'=>$packnum,
				'ordersn'=>get_ordersn('jy_51job_fabulog','ordersn'),
				'type'=>$post['type'],
				'title'=>$title,
				'itemid'=>$post['id'],
				'fee'=>$fee,
				'createtime'=>TIMESTAMP,
				'ispay'=>1
			);
			pdo_insert('jy_51job_fabulog',$insert);
			$id=pdo_insertid();
		}else{
			$topdays=intval($basic['topdays'])?:7;
			$topendtime=TIMESTAMP+$topdays*24*3600;
		}
		pdo_update('jy_51job_job',array('ishot'=>intval($post['ishot']),'topendtime'=>$topendtime),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));	
		exi('操作成功！','','list');
	}
	$id=intval($_RQ['id']);
	$item=$this->pdo_get('item',array('id'=>$id),array('id','mid','ishot','type'));
	$item['packnum']=intval($basic['packnum'])?:7;
	$htmls=array(
		'type'=>'edit',
		'desc'=>'置顶设置',
	);
	$htmls['edit']=array(
		array('type'=>'switch','title'=>'是否扣费','name'=>'iskou','help'=>'如果扣费的话，回自动扣除该主题的发布者相应的置顶费用'),
		array('type'=>'radio','title'=>'置顶方式','name'=>'packname','options'=>'packnames','show'=>array('iskou'=>1)),
		array('type'=>'unitstring','title'=>'置顶天数','name'=>'packnum','unit'=>'天（'.$basic['topfeeday'].'/天）','show'=>array('packname'=>1)),
		array('type'=>'unitstring','title'=>'置顶月数','name'=>'packnum','unit'=>'月（'.$basic['topfeeyue'].'/月）','show'=>array('packname'=>2)),
		array('type'=>'unitstring','title'=>'置顶季数','name'=>'packnum','unit'=>'季（'.$basic['topfeeji'].'/季）','show'=>array('packname'=>3)),
	);
	$return['htmls']=$htmls;
	$return['item']=$item;
	$return['packnames']=array(1=>'按天付费',2=>'按月支付',3=>'按季支付');
	exi($return);
}